//
//  PostionListViewController.m
//  家校互通
//
//  Created by 姬鑫宇 on 15/4/29.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "PostionListViewController.h"
#import "PostionCell.h"
#import "MapViewController.h"
#import "CoModel.h"
@interface PostionListViewController ()<ConnectControlDelegate>{
    NSMutableArray *postionList;
    NSArray *testArray;
    ConnectControl *connectCtr;
}

@end

@implementation PostionListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    postionList             = [[NSMutableArray alloc]initWithCapacity:0];
//    testArray = [NSArray arrayWithObjects:@"862492011033426",@"862492011027386",@"862492011037096", @"862492011028947",nil];
    testArray               = [NSArray arrayWithObjects:@"02894",nil];
    _tableView.delegate     = self;
    _tableView.dataSource   = self;
    self.title              = @"手环定位";
    [Extra getMorePosWithBlock:^(NSString *resultStr, NSArray *posts, NSError *error) {
        postionList = [NSMutableArray arrayWithArray:posts];
        [_tableView reloadData];
    } withSNS:testArray];
    ExtraPostion *postion   = [[ExtraPostion alloc]init];
    postion.lng             = 116.30916;
    postion.lat             = 40.0608;
    postionList             = [NSMutableArray arrayWithObjects:postion, nil];
    // Do any additional setup after loading the view.
    
    connectCtr = [ConnectControl showForView:self.view];
    connectCtr.delegate=self;
    
    if (connectCtr.superview!=nil && connectCtr.loading==NO)
    {
        [connectCtr setLoading:YES];
    }
}

- (void)connect{
    //
    [CoModel getWristbands:^(BOOL result, NSMutableArray *wristbands, NSError *error) {
        [ConnectControl removeFromView:self.view];
        
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -TableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;

}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return postionList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ExtraPostion *postion   = [postionList objectAtIndex:indexPath.row];

    static NSString *cellId = @"PostionCell";
    PostionCell *cell       = [tableView dequeueReusableCellWithIdentifier:cellId];

    [cell setContentWithExtraPostion:postion];
    cell.nameLB.text        = [testArray objectAtIndex:indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ExtraPostion *postion   = [postionList objectAtIndex:indexPath.row];

    MapViewController *map  = [self.storyboard instantiateViewControllerWithIdentifier:@"MapViewController"];
    map.lng                 = postion.lng;
    map.lat                 = postion.lat;
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [self.navigationController pushViewController:map animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
